package server.connector;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;

/*
封装输出流,将输入转换为指定字符集的字节流,重写了输出的方法,调用这些方法后会自动调用刷新缓冲区的方法,
是否真的刷新取决于其封装流的commit变量
 */
/*
2023/1/26 该类内容全部写完,后续直接使用,无需修改
by cyl
 */
public class ResponseWriter extends PrintWriter {
    protected ResponseStream stream = null;

    public ResponseWriter(OutputStreamWriter writer, ResponseStream stream) {
        super(writer);
        this.stream = stream;
        this.stream.setCommit(false);
    }

    @Override
    public void flush() {
        stream.setCommit(true);
        super.flush();
        stream.setCommit(false);
    }

    @Override
    public void print(boolean b) {
        super.print(b);
        super.flush();
    }

    @Override
    public void print(char c) {
        super.print(c);
        super.flush();
    }

    public void print(char ca[]) {
        super.print(ca);
        super.flush();
    }

    public void print(double d) {
        super.print(d);
        super.flush();
    }


    public void print(float f) {
        super.print(f);
        super.flush();
    }

    public void print(int i) {
        super.print(i);
        super.flush();
    }

    public void print(long l) {
        super.print(l);
        super.flush();
    }

    public void print(Object o) {
        super.print(o);
        super.flush();
    }


    public void print(String s) {
        super.print(s);
        super.flush();
    }

    public void println() {
        super.println();
        super.flush();
    }

    public void println(boolean b) {
        super.println(b);
        super.flush();
    }


    public void println(char c) {
        super.println(c);
        super.flush();
    }

    public void println(char ca[]) {
        super.println(ca);
        super.flush();
    }

    public void println(double d) {
        super.println(d);
        super.flush();
    }


    public void println(float f) {
        super.println(f);
        super.flush();
    }

    public void println(int i) {
        super.println(i);
        super.flush();
    }


    public void println(long l) {
        super.println(l);
        super.flush();
    }


    public void println(Object o) {
        super.println(o);
        super.flush();
    }


    public void println(String s) {
        super.println(s);
        super.flush();
    }


    public void write(char c) {
        super.write(c);
        super.flush();
    }

    public void write(char ca[]) {
        super.write(ca);
        super.flush();
    }

    public void write(char ca[], int off, int len) {
        super.write(ca, off, len);
        super.flush();
    }


    public void write(String s) {
        super.write(s);
        super.flush();
    }


    public void write(String s, int off, int len) {
        super.write(s, off, len);
        super.flush();
    }

}
